def bubble_sort(arr):
    n = len(arr)
    for i in range(n - 1): 
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr

li = [3, 2, 5, 6, 4, 9, 7, 1]
bubble_sort_result = bubble_sort(li)
print("Bubble sort result: ", bubble_sort_result)  # 输出：[1, 2, 3, 4, 5, 6, 7, 9]